package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.MyCardBean;
import com.mz.ozy.mvp.model.MyCardModel;
import com.mz.ozy.mvp.view.MycardContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class MyCardPresenter extends BasePresenterImpl<MycardContract.View> implements MycardContract.Presenter {

    private MyCardModel mModel;


    public MyCardPresenter() {
        mModel = new MyCardModel();
    }

    @Override
    public void getInfo(Activity activity, String page,String state) {
        mModel.getInfo(activity, page,state)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MyCardBean>(mView) {
                    @Override
                    public void onSuccesss(MyCardBean bean) {
                        mView.getInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void upAccount(Context context, String code) {
        mModel.getExchangeInfo(context, code)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject bean) {
                        mView.getAccountSuccess(bean);
                    }
                });
    }
}
